
(function(){var validationApp = angular.module('registrationForm', []);
// create angular controller
	validationApp.controller('regFormController', ['$scope','$http',function($scope,$http) {
		$scope.helper50words = false;
		$scope.AddUser = function(){
			$.post("InsertUser",
			  { Username :    $scope.Username,
				Password : 	  $scope.Password,
				Nickname : 	  $scope.Nickname,
				PhotoURL : 	  $scope.Photo,
				Description : $scope.Description }
			).then(function(response) {
            	
            	if (response == "Success")
            	{
          
            		$("#errorAlert").hide();
            		$("#SuccesAlert").show();
            		setTimeout(function(){
            			window.location ='\main.html';
            		}, 3000);
            		
            	}
            	else
        		{
            		$("#SuccesAlert").hide();
            		$("#errorAlert").show();	
            		
        		}
            },
				
				    function(returnedData){
				         console.log(returnedData);
				});
		}
			
		$scope.reset = function() {
			$scope.Username = '';
			$scope.Password='';
			$scope.Nickname='';
			$scope.Photo='';
			$scope.Description='';
	        
	      };
	      $scope.test = 0;
	   
	      $scope.checkfiftywords = function(){
	    	  if($scope.Description == undefined){
	    		  return false;
	    		  }else{
	    			  var wordsArray = $scope.Description.split(/\s+/);
	    			  if(wordsArray.length < 50){
	    				  return false;
	    			  }else{
	    				  return true;
	    			  }
	    		  }
	      }
	      
	      $scope.CheckSession = function(){
	    	  if(!$scope.test){
	    		  $.post("CheckSessionUserName",
	    				  { }
	    				).then(function(response) {
	                	
	    					if (response == "Success")
	    					{
	    						alert("Welcome");
//	                			window.location = '\main.html';
	    					}
	    					else
	    					{
	    						//$scope.errLabel="Username,Nickname or Email are incorrect";
	    						alert("Avner");
	    						alert("ERROR");
	            		
	    					}
	    				},
	    				
	    				    function(returnedData){
	    				         console.log(returnedData);
	    					});
	    		$scope.test = 1;
	    	  }
	      };
	}]);
})();